package arrayandlinkedlist

func maxArea(height []int) int {
	if height == nil || len(height) < 2 {
		return 0
	}
	left, right, area := 0, len(height)-1, 0
	for left < right {
		tmp := min(height[left], height[right]) * (right - left)
		if area < tmp {
			area = tmp
		}
		if height[left] < height[right] {
			left++
		} else {
			right--
		}
	}
	return area
}

func min(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}
